<template>
	<view class="pagesdoctorPlusAdd">
	    <searchBox :currentCode='currentCode' @handleSearch='handleSearch'></searchBox>
		<view class="btnBox" >
			<view class="btn">
				<u-button class="custom-style" @click="jumpApplicationAdd" type="primary" 
					size="mini">会诊申请</u-button>
			</view>
		</view>
		<view class="content" v-if="ordersList.length>0">
			<orderItem v-for="(item, index) in ordersList" :key="index" :orderObj='item' title=''
				:itemIndex='index' :btnGroupArr="btnGroupArr" @handleClick="consultationTableButtonClick"></orderItem>
			<view class="loadmoreView">
				<u-loadmore :status="status" />
			</view>
		</view>
		<pagesNoData v-else></pagesNoData>
	</view>
</template>

<script>
	// 加做医嘱订单
	import request from '@/utils/request'
	import orderItem from '@/components/common/orderItem.vue'
	import {
		mapState
	} from 'vuex'
	import {
		findDoctorSaveOrdersList
	} from '@/api/platform/doctorPlusAdd.js'


	export default {
		components: {
			orderItem
		},
		computed: {
			...mapState({
				userInfo: state => state.user.userInfo,
			}),
		},
		props: ['currentCode'],
		data() {
			return {
				ordersList: [],
				btnGroupArr: [
                    {
                    		label: '快递',
                    		functionKey: 'receive'
                    	},
                    
                    	{
                    		label: '详情',
                    		functionKey: 'details'
                    	},
                    	{
                    		label: '切片',
                    		functionKey: 'slicedetails'
                    	},
						{
							label: '服务提醒',
							functionKey: 'infodetails'
						},
						{
							label: '沟通',
							functionKey: 'chat'
						},
				],
				status: 'loadmore',
				totalPages: 0,
				filterForm: {
					id: null,
					serialNumber: '',
					serviceStatus: '',
					ordersStatus: '',
					name: '',
					contact: '',
					doctor: '',
					sex: '',
					sendDoctorTel: '', // 联系电话
					endOperationTime: '', // 结束时间
					startOperationTime: '', // 起始时间
					orderType: '', //订单类型
					page: 0,
					size: 10
				},
			};
		},
		mounted() {
			this.diagnosisTableRequest()
		},
		methods: {
			consultationTableButtonClick(functionKey, row) { // 总的事件方法
			    this.functionKey=functionKey
				this[functionKey](row)
			},
			//快递
			receive(row) {
				// if (row.expressCount > 0) {
					this.$store.commit('setDetailObj', row)
					uni.navigateTo({
						url: '/subPackages/my/deliveryList/deliveryList'
					})
				// } 
				// else {
				// 	this.$modal.showToast('暂无快递')
				// }
				
			},
			//沟通
			chat(row){
				uni.navigateTo({
					url: `/subPackages/message/history/history?orderId=${row.id}`
				})
			},
			//消息
			infodetails(row) {
				console.log('row--',row)
				this.$store.commit('setDetailObj', row)
				uni.navigateTo({
					url: `/subPackages/my/reminder/reminder?orderId=${row.id}`
				})
			},
			//切片
			slicedetails(row) {
				if (row.slicesNumber > 0) {
					uni.navigateTo({
						url: `/subPackages/patient/detail/detail?id=${row.id}&current=3`
					})
				} else {
					this.$modal.showToast('暂无切片')
				}
			},
			details(row) { //详情
				uni.navigateTo({
					url: `/subPackages/patient/detail/detail?id=${row.id}`
				})
			},
			handleSearch(data) {
				console.log('doctorPlusAdd---', data)
				this.ordersList = []
				this.filterForm = data
				this.diagnosisTableRequest()

			},
			
			scrolltolower() {
				let that = this;
				this.status = 'loading';
				this.filterForm.page = ++this.filterForm.page;
				setTimeout(() => {
					if (this.filterForm.page < this.totalPages) {
						this.status = 'loadmore'
						that.diagnosisTableRequest()
					} else {
						this.status = 'nomore'
					}

				}, 600)
			},
			diagnosisTableRequest() { //会诊申请
				findDoctorSaveOrdersList(this.filterForm).then(res => {
					if (res.code == 200) {
						this.totalPages =Math.ceil(res.pageInfo.total/res.pageInfo.size) 
						let ordersList = res.data
						this.ordersList.push(...ordersList)
						
						
					}
				})

			},
			jumpApplicationAdd(){
				uni.navigateTo({
					url:'/subPackages/service/institutionApply/institutionApply'
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.pagesdoctorPlusAdd {
		height: 100%;

		.content {
			height: 100%;
		}
		.btnBox{
			display: flex;
			justify-content: flex-end;
			.btn{
				width: 180rpx;
				.custom-style{
					font-size: 30rpx;
				}
			}
		}
	}
</style>